#coding=UTF-8
import requests
import json

# 引入自定义的keystone模块
import keystone
keystone_s=keystone.getToken()

#nova(compute)端点地址：
glance_url="http://192.168.100.10:9292/v2/images"
#定义请求头
headers={
    "X-Auth-Token":keystone_s['token'],
    "Content-Type": "application/json"
}
# body={
# 	"container_format": "bare",
# 	"disk_format": "qcow2",
# 	"name": "cirros",
# 	"id": "d2173dd3-7ad6-4362-baa6-a68bce3565cv"
# }
body={
	"container_format": "bare",
	"disk_format": "qcow2",
	"name": "cirros"
}

#发送请求
req=requests.post(glance_url,headers=headers,data=json.dumps(body))

#如果报错请检测body中的id是否唯一
print(json.dumps(req.json(),sort_keys=True,indent=4))
